﻿using MovingChame.WindowsStoreApp.Common;
using MovingChame.WindowsStoreApp.Helpers;
using MovingChameLibrary;
using MovingChameLibrary.Models;
using MovingChameLibrary.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace MovingChame.WindowsStoreApp.UIModule
{
    public sealed partial class OfficialTourPage : LayoutAwarePage
    {
        private OfficialTourViewModel _viewModel;
        public OfficialTourViewModel ViewModel
        {
            get { return this._viewModel; }
            set
            {
                this._viewModel = value;
                this.DataContext = value;
            }
        }

        public OfficialTourPage()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            SearchPaneHelper.DeactivateSearchPane();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            SearchPaneHelper.Frame = this.Frame;
            SearchPaneHelper.ActivateSearchPane();
        }

        protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            Geoposition currentPosition = await GeolocationHelper.GetCurrentLocation();
            ViewModel = new OfficialTourViewModel(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);
        }

        private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var tour = e.ClickedItem;
            this.Frame.Navigate(typeof(TourOverviewPage), (tour as Tour).Id);
        }

        private void TourKindSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }
    }
}